#include "rclcpp/rclcpp.hpp"
#include "custom_srv_msg/msg/custom_msg.hpp"


using namespace std::chrono_literals;


namespace custom_msg
{
    class custom_msg_pub :public rclcpp::Node
    {
    private:
        rclcpp::TimerBase::SharedPtr timer_;
        rclcpp::Publisher<custom_srv_msg::msg::CustomMsg>::SharedPtr pub_;
        void Timer_cb()
        {
            custom_srv_msg::msg::CustomMsg message;
            message.i_a = 10;
            RCLCPP_INFO(this->get_logger(),std::to_string(message.i_a).c_str());
            message.str_b = "This is custom_msg";
            pub_->publish(message);
        }
    public:
        custom_msg_pub(/* args */);
        ~custom_msg_pub();
    };
    
    custom_msg_pub::custom_msg_pub(/* args */) :Node("custom_msg_pub_node")
    {
        pub_ =this->create_publisher<custom_srv_msg::msg::CustomMsg>("custom_msg",10);
        timer_ =this->create_wall_timer(500ms,std::bind(&custom_msg_pub::Timer_cb,this));   //必须接收保存返回值
    }
    
    custom_msg_pub::~custom_msg_pub()
    {
    }
    
} // namespace custom_msg_pub


int main(int argc, char const *argv[])
{
    rclcpp::init(argc,argv);
    auto node = std::make_shared<custom_msg::custom_msg_pub>();
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}
